<?php 
//加载pdo连接需要的配置
require "./pdoconfig.php";

//连接数据库
try {
	$pdo = new PDO(DSN,USER,PASS);
	// var_dump($pdo);
	
	// 设置PDO 连接属性
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
	
} catch (PDOException $e) {
	echo $e->getMessage();
	exit;
}


//验证数据
try {
	$data=$_POST;
	// var_dump($data);
	$user=$data['user'];
	$pass=$data['pass'];

	$sql="select * from user2 where name= ? and pass=? ";
	// echo $sql;
	
	$stmt=$pdo->prepare($sql);
	$stmt->bindParam(1,$user);
	$stmt->bindParam(2,$pass);

	$stmt->execute();

	if ($stmt->rowCount() > 0) {
		echo "登录成功";
	} else {
		echo "登录失败";
	}
	
} catch (PDOException $e) {
	echo $e->getMessage();
	exit;
}